package com.lwj.securitydemo.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimeAspect {

    @Around("execution(* com.lwj.securitydemo.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("time aspect 方法被调用！");
        long start = System.currentTimeMillis();

        //  获取切片方法的参数
        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            System.out.println("args : " + arg);
        }

        //  执行切片的方法
        Object obj = pjp.proceed();

        System.out.println("time aspect 耗时: " + (System.currentTimeMillis() - start));
        System.out.println("time aspect 方法结束！");
        return obj;
    }

}
